#include "put_file.h"

Put_File::Put_File(QObject *parent) :
    QObject(parent)
{

}


void Put_File::initLogin(QString ip,QFtp *ftp,QString &fileName)
{
    this->ftp=ftp;
    connect(ftp,SIGNAL(commandFinished(int,bool)),this, SLOT(ftpCommandFinished(int,bool)));
    file=new QFile(fileName);
    if(!file->open(QIODevice::ReadOnly))
    {
        qDebug()<<"open QIODevice fail";
        delete file;
        return;
    }
    ftp->connectToHost(ip,21);
    ftp->login();

    qDebug()<<fileName;
    ftp->put(file,fileName.split("/").last());
    qDebug()<<fileName.split("/").last();
}

void Put_File::ftpCommandFinished(int p, bool error)
{
    if (ftp->currentCommand() == QFtp::Put)
    {
        if (error)

               qDebug()<<"Put  faile";
        else
            {
                qDebug()<<"Put  sucess";

            }
        file->close();
        delete file;
        return;
    }
}
